<!DOCTYPE html>
<html>
<head>
	<title>梦来梦往专属博客首页</title>
	<meta charset="utf-8"/>
</head>
<body>
<#include "public/import.html"/>
<#include "public/nav.html"/>

<div id="mgbody" class="container">	
	<div class="topDiv">
		<div class="address">
			<span>MgBlog首页 
			<#if aSort??>
				&gt; ${aSort.name}
			</#if>
			</span>
		</div>
		<!-- 搜索框 -->
		<div id="search" class="row">
		    <div class="input-group">
		      <input type="text" class="form-control">
		      <span class="input-group-btn">
		        <a class="btn btn-default" type="button">搜索</a>
		      </span>
		    </div><!-- /input-group -->
		</div><!-- /.row -->
	</div>
	<!-- 加入文章分类在右边 -->
	<div class="article-left">
		<!-- 最新文章 -->
		<div class="article-div">
			<#if page.totalPage lt 1>
				<div class="no-blog-info">
					该分类暂无博文...
				</div>
			</#if>
			<#if page.totalPage gte 1>
				<#list page.list as a>
				<div class="grid9">
		          	<h4><a href="nc_showArticle.do?id=${a.id}">${a.title}</a></h4>
		          	<div style="border-bottom: 1px solid #dddddd;color:gray;width:100%;">
		          		${a.user.nickName}　${a.addTime?string("yyyy-MM-dd HH:mm:ss")}　分类：<strong>${a.articleSort.name}</strong>
		          	</div>
		          	<div class="article-area">${a.content}</div>
		         	<div class="line">
		         		<a title="查看全文" class="pull-right" href="nc_showArticle.do?id=${a.id}"><img style="width:32px;" src="${basePath}pages/image/icon/readMore.png"></a>
		         	</div>
		        </div>
		        </#list>
		  	</#if>
		</div>
		<#if page.totalPage gte 1>
			<#assign path="${basePath}nc_toIndex.do"/>
			<#include "public/pager.html"/>
		</#if>
	</div>
	<div class="on-right">
		<#if loginUser??>
			<div class="self-info">
			  <div class="mg-panel-title">个人信息</div>
			  <div class="panel-body">
			    	${loginUser.userName}
			  </div>
			</div>
		</#if>
		<div class="sort-div">
		  <div class="mg-panel-title">文章分类</div>
		  <div class="mg-panel-body">
		  	<ul id="sortUl">
		  		<li class="allSort">
		  			<a href="nc_toIndex.do">所有分类</a><span style="color:gray;">(-)</span>
	  				<span class="pull-right">
	  					<a onclick="doOrderBy(this);" href="javascript:void(0);">升序</a>
	  					<a onclick="doOrderBy(this);" href="javascript:void(0);">降序</a>
	  				</span>
		  		</li>
		  		<#list sortList as sort>
		    		<li><a href="nc_toIndex.do?sortId=${sort.id}">${sort.name}</a><span style="color:gray;">(${sort.articleNum})</span>
		    			<span class="pull-right" style="color:gray;">${sort.createTime?string("yyyy-MM-dd")}</span>
		    		</li>
		    	</#list>
		  	</ul>
		    	
		  </div>
		</div>
	</div>
</div>

<#include "public/copyright.html"/>
<script type="text/javascript">
	$(function(){
		
	});
	//使用ajax来完成升序和降序
	function doOrderBy(t){
		var _str = $(t).text();
		if(_str == "升序"){
			$.ajax({
				type: "post",
			  	url: getRootPath() + "/nc_orderBy.do",
			  	data:{"order":"createTime asc"},
			  	dataType: "json",
			  	success:function(res){
			  		doShowReturnSort(res);
			  	},
			  	error:function(){
			  		alert("ajax error");
			  	}

			});
		}else if(_str == "降序"){
			$.ajax({
				type: "post",
			  	url: getRootPath() + "/nc_orderBy.do",
			  	data:{"order":"createTime desc"},
			  	dataType: "json",
			  	success:function(res){
			  		doShowReturnSort(res);
			  	},
			  	error:function(){
			  		alert("ajax error");
			  	}

			});
		}
	}
	function doShowReturnSort(res){
		var allLi = $(".allSort").clone();
		$(allLi).children("div").children("span").text("－");
  		$("#sortUl").children("li").remove();
  		$("#sortUl").append(allLi);
  		$(res).each(function(){
  			var date = new Date(this.createTime.time);
  			var str_date = date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
  			var liElement = $("<li><a href='nc_toIndex.do?sortId="+ this.id +"'>"+ this.name +"</a><span style='color:gray;'>"+
  				"("+ this.articleNum +")</span>"+
    			"<span class='pull-right' style='color:gray;'>"+ str_date +"</span></li>");
  			$("#sortUl").append(liElement);
  		});
	}
</script>
</body>
</html>